<?php

/** 
 * ALog - Abstract class about loggable item
 * 
 * @author polux
 * 
 */
abstract class ALog {
		
	// *********************** Attributes *********************** //	
	/**
	 * Logged Object reference
	 * @var mixed ILoggable
	 * @access protected
	 */
	protected $_o_loggedObject;
	/**
	 * Message
	 * @var string
	 * @access protected
	 */
	protected $_s_msg;
	/**
	 * Date of Log 
	 * 
	 * @var timestamp
	 * @access protected
	 */
	protected $_d_logTimestamp;
	/**
	 * Stack trace of Log Item
	 * 
	 * @var string
	 * @access protected
	 */
	protected $_s_stacktrace;
	/**
	 * Stack trace of Log Item
	 *
	 * @var string
	 * @access protected
	 */
	protected $_i_levelOfLog;
	/**
	 * LogManager
	 *
	 * @var LogManager 
	 * @access protected
	 */
	protected $_o_logManager;
	
	// *********************** Constructor *********************** //
	/**
	 * Default Constructor
	 * 
	 * @param ILoggableItem $p_o_object
	 */
	function __construct(ILoggableItem &$p_o_object = null) {
		$this->_o_loggedObject = $p_o_object;
		$this->setTimestamp();
	}
	
	// *********************** Public Methods *********************** //
	/**
	 * registerLogManager - Refer LogManager Object
	 * 
	 * @param LogManager $p_o_logManagerObj
	 */
	public function registerLogManager(LogManager &$p_o_logManagerObj)
	{
		$this->_o_logManager = $p_o_logManagerObj;
	}
	/**
	 * setLogMessage
	 * 
	 * @param string $p_s_msg
	 */
	public function setLogMessage($p_s_msg)
	{
		$this->_s_msg = $p_s_msg;
	}
	/**
	 * getLogMessage
	 * 
	 * @return string
	 */
	public function getLogMessage()
	{
		return $this->_s_msg;
	}
	/**
	 * getTimestamp - get timestamp of log item
	 *
	 * @return long timestamp
	 */
	public function getTimestamp()
	{
		return $this->_d_logTimestamp;
	}
	/**
	 * getLogObject_InternalID - Return ID of logged items
	 * 
	 * @return string
	 */
	public function getLogObject_InternalID()
	{
		
		return $this->_o_loggedObject->getInternalID();
	}
	/**
	 * getFormattedLogMessage - Layout of message
	 * 
	 * @return string
	 */
	abstract function getFormattedLogMessage();	
	
	// *********************** Protected methods *********************** //
	/**
	 * setTimestamp - Set timestamp of log item
	 * 
	 * @access protected
	 */
	protected function setTimestamp()
	{
		$this->_d_logTimestamp = time();
	}	
}


class LogInfo extends ALog
{
	public function __construct($p_o_object,$p_s_msg)
	{
		parent::__construct($p_o_object);
		$this->setLogMessage($p_s_msg);
	}
	
	public function getFormattedLogMessage()
	{
		return sprintf(LOG_INFO_PATTERN,date("Y m d-h:i:s",$this->getTimestamp()),$this->getLogObject_InternalID(),$this->getLogMessage());
	}
}

class LogWarn extends ALog
{
	public function __construct($p_o_object,$p_s_msg)
	{
		parent::__construct($p_o_object);
		$this->setLogMessage($p_s_msg);
	}

	public function getFormattedLogMessage()
	{
		return sprintf(LOG_WARN_PATTERN,date("Y m d-h:i:s",$this->getTimestamp()),$this->getLogObject_InternalID(),$this->getLogMessage());
	}
}

class LogError extends ALog
{
	public function __construct($p_o_object,$p_s_msg)
	{
		parent::__construct($p_o_object);
		$this->setLogMessage($p_s_msg);
	}

	public function getFormattedLogMessage()
	{
		return sprintf(LOG_ERR_PATTERN,date("Y m d-h:i:s",$this->getTimestamp()),$this->getLogObject_InternalID(),$this->getLogMessage());
	}
}

class LogBreak extends ALog
{
	public function getFormattedLogMessage()
	{
		return "------------------------------------------------------------------------------------------------------------------------";
	}
}

class LogTitle extends ALog
{
	public function __construct($p_s_title)
	{
		parent::__construct();
		$this->setLogMessage($p_s_title);
	}
	
	public function getFormattedLogMessage()
	{
		$l_s_msg = "------------------------------------------------------------------------------------------------------------------------\n"
				."-  ".$this->_s_msg.
		"\n"."------------------------------------------------------------------------------------------------------------------------";
		return $l_s_msg;
	
	}
}

class LogSubTitle extends ALog
{
	public function __construct($p_s_title)
	{
		parent::__construct();
		$this->setLogMessage($p_s_title);
	}

	public function getFormattedLogMessage()
	{
		$l_s_msg = "-  ".$this->_s_msg."\n"."**************************************************************************";
		return $l_s_msg;

	}
}


?>